let express = require('express');

let errinfo = require('../errinfo.js');
let bookBusiness = require('../business/book');

let router = module.exports = express.Router();


/**
 * add book
 */
// check input
router.post('/', bookBusiness.addCheckInput);
// add
router.post('/', bookBusiness.add);
// add a book
router.post('/', bookBusiness.addSuc);

/**
 * param bookId
 */
let bookIdPath = '/:bookId([0-9a-fA-F]{24})';
router.param('bookId', bookBusiness.param);
/**
 * delete book
 */
// check exist
router.delete(bookIdPath, bookBusiness.checkExist);
// check delete
router.delete(bookIdPath, bookBusiness.checkDelete);
// suc
router.delete(bookIdPath, bookBusiness.deleteSuc);

/**
 * update book
 */
// check exist
router.put(bookIdPath, bookBusiness.checkExist);
// check delete
router.put(bookIdPath, bookBusiness.checkDelete);
// check isbn10 duplicate
router.put(bookIdPath, bookBusiness.updateCheckIsbn10Duplicate);
// check isbn13 duplicate
router.put(bookIdPath, bookBusiness.updateCheckIsbn13Duplicate);
// update book
router.put(bookIdPath, bookBusiness.update);
// update suc
router.put(bookIdPath, bookBusiness.updateSuc);

/**
 * get one book
 */
// get book
router.get(bookIdPath, bookBusiness.checkExist);
// check delete
router.get(bookIdPath, bookBusiness.checkDelete);
// get suc
router.get(bookIdPath, bookBusiness.getSuc);

/**
 * get one book by isbn
 */
let bookIsbnPath = '/isbn/:isbn';
// get book from database
router.get(bookIsbnPath, bookBusiness.getByIsbnFromDB);
// get book from douban
router.get(bookIsbnPath, bookBusiness.getByIsbnFromDouban);
// get book from amazon
router.get(bookIsbnPath, bookBusiness.getByIsbnFromAmazon);
// save
router.get(bookIsbnPath, bookBusiness.getByIsbnSaveBook);
// suc
router.get(bookIsbnPath, bookBusiness.getByIsbnSuc);

/**
 * list book
 */
// page info
router.get('/', bookBusiness.page);
// count
// router.get('/', bookBusiness.calcCount);
// book list
router.get('/', bookBusiness.list);
// list suc
router.get('/', bookBusiness.listSuc);


/**
 * list book names
 */
// book list
router.get('/option/name', bookBusiness.listNames);
// list suc
router.get('/option/name', bookBusiness.listNamesSuc);

/**
 * list book names from net
 */
// book list
router.get('/option/nameFromNet', bookBusiness.listNamesFromNet);
// list suc
router.get('/option/nameFromNet', bookBusiness.listNamesFromNetSuc);


